/*
 *  Copyright (c) 2022 ZhuHai Jieli Technology Co.,Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
 
 /*********************************************************************************************
    *   Filename        : reboot.S

    *   Description     :

    *   Author          : Bingquan

    *   Email           : bingquan_cai@zh-jieli.com

    *   Last modifiled  : 2018-07-09 16:24

    *   Copyright:(c)JIELI  2011-2017  @ , All Rights Reserved.
*********************************************************************************************/

.section .stack, "a"
         .space 0x400
         .global _ustack
_ustack:

    .extern  _stack
#define hi(x) ((x)>>16)
#define lo(x) ((x)&0xffff)
.section .non_volatile_ram_code
    .align 2
    .global _reboot_start
    .extern memset
    .type _reboot_start ,@function
    .org 0

.extern poweroff_post
.extern nv_watchdog_close

_reboot_start:
    sp  = _ustack   ;// for idle
    usp = _ustack   ;// for interrupt
    ssp = _stack;// for interrupt

    call nv_watchdog_close

    r3 = bss_begin  ;//movh  r0, bss_begin
    r1 = 0          ;//mov   r1,0
    r2 = bss_size   ;//movh  r2, bss_size
    ; r2 >>= 2;
1:
    rep r2{
        b[r3++] = r1
    }
    if(r2 != 0) goto 1b

    goto  poweroff_post

